import { findAllcategory } from '@/api/category'
import { topCategory } from '@/api/constants'
// 分类模块
export default {
  namespaced: true,
  state () {
    return {
      // 分类信息集合
      list: topCategory.map(item => ({ name: item }))
    }
  },
  mutations: {
    setlist (state, payload) {
      state.list = payload
    },
    show (state, item) {
      const category = state.list.find(el => el.id === item.id)
      category.open = true
    },
    hide (state, item) {
      const category = state.list.find(el => el.id === item.id)
      category.open = false
    }
  },
  actions: {
    async getlist (store) {
      const { result } = await findAllcategory()
      // console.log(result)
      store.commit('setlist', result)
    }
  }
}
